/*******************************************************************************
																				
	DESCRIPTION: 	This do file does bootstrapping on the hold-out sample to
					check the variability of R-squared.				
	
*******************************************************************************/

clear all
global id_code 126

*******************************************************************************
 * Import the data
*******************************************************************************
local model Full
local vars _
local year 2006

use "${data}/003_MainWithEnsemblePred_`model'`vars'`year'.dta", clear

* Keep only relevant observations:
keep if !missing(emplAft6M_0M_In, p_emplAft6M_0M_In)

* Program:
program myreg, rclass
	version 17
	
	reg emplAft6M_0M_In p_emplAft6M_0M_In
	local r2 = e(r2)
	
	correlate emplAft6M_0M_In p_emplAft6M_0M_In, cov
	local cov = r(C)[2, 1]
	
	return scalar r2 = `r2'
	return scalar cov = `cov'
end

myreg

* Run bootstrap command:
bootstrap r(r2) r(cov), reps(500) seed(2110) verbose ///
	saving("${data}/${id_code}_Bootstrapping_`model'`vars'`year'.dta", replace) ///
	: myreg
